<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>防抖节流</title>
</head>
<body>
    <input type="text" class="search">
    <script>
        function debounce(fn,delay=500){
            let timer = null
            return function(){
                clearTimeout(timer)
                timer = setTimeout(() => {
                    fn.call(this,arguments)
                },delay)
            }
        }

        let fc = () =>{
            console.log(input.value)
        }
        let func = debounce(fc)
        let input = document.querySelector('.search')
        input.addEventListener('keyup',() => {
            func()
        })
    </script>
</body>
</html>